// 地址控制器
import 'package:cbec_app/components/base/base_ctr.dart';
import 'package:cbec_app/components/common/city_picker.dart';
import 'package:cbec_app/components/http/network.dart';
import 'package:cbec_app/entity/user_center/address_list_entity.dart';
import 'package:cbec_app/routes/routes.dart';
import 'package:cbec_app/utils/AddressParse.dart';
import 'package:cbec_app/utils/AppData.dart';
import 'package:cbec_app/utils/EventMgr.dart';
import 'package:cbec_app/utils/GlobalData.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:cbec_app/utils/logger.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../components/app_conifg.dart';

class PrivacySettingCtr extends BaseController {
  //个性化推荐开关
  bool pr = false;

  @override
  void onInit() {
    super.onInit();
    getUserInfo();
  }

  //个性化配置
  void modifyRecommendConfig() async {
    Tools.showLoading();
    Map<String, dynamic> params = {};
    params['client'] = GetPlatform.isIOS ? AppConfig.clientIos : AppConfig.clientAndroid;
    return Network.modifyRecommendConfig(params).then((value) {
      Tools.hideLoading();
      AppData.isOpnRecommendConfig = value;
      print('value ====== $value');
      pr = value;
      getUserInfo();
    }).catchError((onError) {
      Tools.hideLoading();
    });
  }

  //个性化配置
  void getUserInfo() async {
    Tools.showLoading();
    return Network.getUserInfo().then((value) {
      Tools.hideLoading();
      print('value1 ===== $value');
      pr = value['recommendConfig'] == 0 ? false : true;
      AppData.isOpnRecommendConfig = pr;

      print('AppData.isOpnRecommendConfig ==== ${AppData.isOpnRecommendConfig}');
      update();
      EventMgr.send(EventType.refreshLogin);
    }).catchError((onError) {
      Tools.hideLoading();
    });
  }
}
